package jmine.tec.aom.domain;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

import jmine.tec.persist.annotation.DiscriminatorComment;

import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.utils.reflection.ReflectionUtils;

/**
 * Defines an enum-based {@link Property}.
 * <p>
 * {@link PropertyValue} instances of this {@link Property} will be enforced to be of valid entries in the specified enum.
 * 
 * @author reginaldo.kamiya
 * @since 01/12/2009
 */
@Entity
@DiscriminatorValue(value = "1")
@DiscriminatorComment("ENUMERADA")
public class EnumProperty extends Property {

    private String fullyQualifiedName;

    /**
     */
    public EnumProperty() {
        super();
    }

    /**
     * @return the fully qualified name of the enum class
     */
    @NotNull
    @Column(name = "FULLY_QUALIFIED_NAME")
    @Documentation("NOME DA CLASSE A SER UTILIZADA EM REFLECTION")
    public String getFullyQualifiedName() {
        return this.fullyQualifiedName;
    }

    /**
     * @param fullyQualifiedName the fully qualified name of the enum class
     */
    public void setFullyQualifiedName(String fullyQualifiedName) {
        this.fullyQualifiedName = fullyQualifiedName;
    }

    /**
     * @return the actual {@link Enum} type to be used
     * @throws ClassNotFoundException if the given type cannot be found
     */
    @Transient
    @SuppressWarnings("unchecked")
    public Class<? extends Enum> getEnumType() throws ClassNotFoundException {
        return (Class<? extends Enum>) ReflectionUtils.findClass(this.getFullyQualifiedName());
    }
}
